#ifndef DOCPROCESS_H
#define DOCPROCESS_H
#include <QString>
#include <QMap>
#include <QList>
#include <Qsci/qsciapis.h>

class DocProcess
{
public:
    DocProcess();

    void LoadAvatarDoc();
    void LoadPluginDoc();
    void LoadSceneDoc();

    void AddAPI(QsciAPIs* apis);

private:
    /**
     * @brief 接口文档定义
     */
    class ScriptApi
    {
    public:
        // 常量
        bool constant;
        // 函数/常量名称
        QString name;
        // 描述
        QString desc;
        // 函数参数
        QString param;
        // 函数返回值
        QString ret;
        // 函数参数个数
        int paramCount;

        /**
         * @brief 构造函数
         * @param name
         * @param desc
         * @param param
         * @param ret
         */
        ScriptApi(QString name, QString desc, QString param, QString ret)
        {
            this->constant = false;
            this->name = name;
            this->desc = desc;
            this->param = param == "-" ? "" : param;
            this->ret = ret == "-" ? "" : ret;
            this->paramCount = param.isEmpty() ? 0 : param.count(',') + 1;
        }

        /**
         * @brief 构造函数
         * @param name
         * @param desc
         */
        ScriptApi(QString name, QString desc)
        {
            this->constant = true;
            this->name = name;
            this->desc = desc;
        }

        /**
         * @brief 重载 ToString
         * @return
         */
        QString ToString()
        {
            if (constant) return name;
            return (name + "(" + param + ")" + (ret.isEmpty() ? "" : " <= " + ret) + " --" + desc).trimmed();
        }
    };

private:
    void insert(QList<std::shared_ptr<ScriptApi>>& apiList, std::shared_ptr<ScriptApi> api);

    // 脚本接口列表文档
    QMap<QString, QList<std::shared_ptr<ScriptApi>>> ScriptApiMap;
    // 场景节点操作文档
    QMap<QString, QList<std::shared_ptr<ScriptApi>>> SceneHandleMap;
};

#endif // DOCPROCESS_H
